#include "LampManager.h"
#include "F3LampInterfaces.h"

void buildLeTurnLamp_TL_EN_FaultFlag(LeTurnLamp_TL_EN_FaultFlag* lastFlag, LeTurnLamp_TL_EN_FaultFlag* newFlag)
{
    if(!Is_TL_EN())
    {
        // Fault
        newFlag->isFault_ = true;
        newFlag->TL_EN_recoveryCount_ = 0;
        // std::cout << "TL_EN fault" << std::endl;
    }
    else
    {
        if(lastFlag->isFault_)
        {
            if(newFlag->TL_EN_recoveryCount_ > 4)
            {
                newFlag->isFault_ = false;
                newFlag->TL_EN_recoveryCount_ = 0;

                // std::cout << "TL_EN recovery" << std::endl;
            }
            else
            {
                newFlag->TL_EN_recoveryCount_++;
                // std::cout << "TL_EN recovering " << newFlag->TL_EN_recoveryCount_ << std::endl;
            }
        }
    }
}

bool IsLampTurnOn(OnOffFlag flag)
{
    return flag == OnOff_On;
}

bool IsSystemGoingToSleep()
{
    return g_SystemSleepWeakupModel.systemState_ == System_Sleep;
}

bool IsSystemInIdle()
{
    return g_SystemSleepWeakupModel.systemState_ == System_Init;
}

bool IsBothPo2AndStarrySkyTurnOff()
{
    return g_StarrySkyView.model_->onOffStatus_ == OnOff_Off && g_Po2LedView.model_->onOffStatus_ == OnOff_Off;
}
